package com.ftg.elvis.service;

import com.ftg.elvis.mapper.AdminProductMapper;
import com.ftg.elvis.pojo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class AdminProductService {

	@Autowired
	AdminProductMapper adminProductMapper;

	public int getCount(String username, String pname) {
		username = username == null ? "" : username;
		pname = pname == null ? "" : pname;
		return adminProductMapper.getCount(username, pname);
	}

	public List<Product> showAll(String username, String pname, int page, int limit) {
		page = (page - 1) * limit;
		username = username == null ? "" : username;
		pname = pname == null ? "" : pname;

		return adminProductMapper.showAll(username, pname, page, limit);
	}

	public int add(Product product) {
		product.setPid(UUID.randomUUID().toString());
		return adminProductMapper.add(product);
	}

	public int update(Product product) {
		return adminProductMapper.update(product);
	}

	public int delete(String pid) {
		return adminProductMapper.delete(pid);
	}

	public String getBid(String username) {
		return adminProductMapper.getBid(username);
	}
}
